home *** CD-ROM | disk | FTP | other *** search
/ SVM Mac 1 / CD-ROM N°1.iso / Utilitaires / Programmation⁄Infos / CDEF Pack 1.1 / CDEF Sampler Program ƒ / sampler.c next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  4.6 KB  |  251 lines  |  [TEXT/KAHL]

  1. /*****
  2.  * bullseye.c
  3.  *
  4.  *    A simple demonstration program to play with the debugger
  5.  *
  6.  *
  7.  *****/
  8.  
  9. #include "samplerMenus.h"
  10. #include "samplerWindow.h"
  11. #include "samplerControls.h"
  12.  
  13. extern    WindowPtr        samplerWindow;
  14. extern    ControlHandle    rocketCntl, timeButtonCntl, timeCntl, dateCntl;
  15. extern    Rect            dragRect;
  16.  
  17. SysEnvRec    gMac;            
  18.  
  19. void InitMacintosh(void);
  20. void HandleMouseDown (EventRecord    *theEvent);
  21. void HandleEvent(void);
  22.  
  23. /****
  24.  * InitMacintosh()
  25.  *
  26.  * Initialize all the managers & memory
  27.  *
  28.  ****/
  29.  
  30. void InitMacintosh(void)
  31.  
  32. {
  33.     MaxApplZone();
  34.     
  35.     InitGraf(&thePort);
  36.     InitFonts();
  37.     FlushEvents(everyEvent, 0);
  38.     InitWindows();
  39.     InitMenus();
  40.     TEInit();
  41.     InitDialogs(0L);
  42.     InitCursor();
  43.  
  44.     SysEnvirons(curSysEnvVers, &gMac);
  45.     
  46.     if (gMac.systemVersion < 0x0700)
  47.         ExitToShell();
  48.  
  49. }
  50. /* end InitMacintosh */
  51.  
  52.  
  53. /****
  54.  * HandleMouseDown (theEvent)
  55.  *
  56.  *    Take care of mouseDown events.
  57.  *
  58.  ****/
  59.  
  60. void HandleMouseDown (EventRecord    *theEvent)
  61.  
  62. {
  63.     WindowPtr    theWindow;
  64.     int            windowCode = FindWindow (theEvent->where, &theWindow);
  65.     
  66.     switch (windowCode)
  67.       {
  68.       case inSysWindow: 
  69.         SystemClick (theEvent, theWindow);
  70.         break;
  71.         
  72.       case inMenuBar:
  73.           AdjustMenus();
  74.         HandleMenu(MenuSelect(theEvent->where));
  75.         break;
  76.         
  77.       case inDrag:
  78.           if (theWindow == samplerWindow)
  79.             DragWindow(samplerWindow, theEvent->where, &dragRect);
  80.             break;
  81.             
  82.       case inContent:
  83.           if (theWindow == samplerWindow)
  84.           {
  85.           short            cntlPart;
  86.           Point            clickPt = theEvent->where;
  87.           ControlHandle    foundCntl;
  88.           
  89.               if (theWindow != FrontWindow())
  90.                   SelectWindow(samplerWindow);
  91.                 else
  92.                 {
  93.                     GlobalToLocal(&clickPt);
  94.                     
  95.                   cntlPart = FindControl(clickPt, samplerWindow, &foundCntl);
  96.                   if (cntlPart)
  97.                   {
  98.                       if (( foundCntl != dateCntl)&&( foundCntl != timeCntl ))
  99.                       {
  100.                           if (cntlPart = TrackControl( foundCntl, clickPt, 0 ))
  101.                           {
  102.                               if ( foundCntl == rocketCntl)
  103.                               {
  104.                                   SysBeep(20);
  105.                               }
  106.                               else if (foundCntl == timeButtonCntl)
  107.                               {
  108.                                   SetCtlValue( timeButtonCntl, !GetCtlValue(timeButtonCntl));
  109.  
  110.                                 if (GetCtlValue( timeButtonCntl))
  111.                                 {
  112.                                     HiliteControl(timeCntl, 0);
  113.                                     HiliteControl(dateCntl, 0);
  114.                                 }
  115.                                 else
  116.                                 {
  117.                                     HiliteControl(timeCntl, 255);
  118.                                     HiliteControl(dateCntl, 255);
  119.                                 }
  120.  
  121.                               }
  122.                           }
  123.                       }
  124.                       else
  125.                       {
  126.                           if ( foundCntl == dateCntl)
  127.                           {
  128.                               SetCtlValue( timeCntl, 0 );
  129.                               HandleDateCDEFClick(clickPt);
  130.                           }
  131.                           else
  132.                           {
  133.                               SetCtlValue( dateCntl, 0 );
  134.                               HandleTimeCDEFClick(clickPt);
  135.                           }
  136.                       }
  137.                   }
  138.                   else
  139.                   {
  140.                       SetCtlValue( timeCntl, 0 );
  141.                       SetCtlValue( dateCntl, 0 );
  142.                   }
  143.               }
  144.                               
  145.                   
  146.            }
  147.           break;
  148.           
  149.       case inGoAway:
  150.           if (theWindow == samplerWindow && 
  151.               TrackGoAway(samplerWindow, theEvent->where))
  152.           HideWindow(samplerWindow);
  153.             break;
  154.       }
  155. }
  156. /* end HandleMouseDown */
  157.  
  158.  
  159. /****
  160.  * HandleEvent()
  161.  *
  162.  *        The main event dispatcher. This routine should be called
  163.  *        repeatedly (it  handles only one event).
  164.  *
  165.  *****/
  166.  
  167. void HandleEvent(void)
  168.  
  169. {
  170.     int                ok;
  171.     EventRecord        theEvent;
  172.     ControlHandle    curCntl;
  173.  
  174.     HiliteMenu(0);
  175.     SystemTask ();        /* Handle desk accessories */
  176.     
  177.     ok = GetNextEvent (everyEvent, &theEvent);
  178.     if (ok)
  179.         switch (theEvent.what)
  180.         {
  181.             case mouseDown:
  182.                 HandleMouseDown(&theEvent);
  183.                 break;
  184.             
  185.             case keyDown: 
  186.             case autoKey:
  187.                 if ((theEvent.modifiers & cmdKey) != 0)
  188.                 {
  189.                       AdjustMenus();
  190.                       HandleMenu(MenuKey((char) (theEvent.message & charCodeMask)));
  191.                   }
  192.                 break;
  193.             
  194.             case updateEvt:
  195.                 BeginUpdate(samplerWindow);
  196.                 DrawSampleWindow(((WindowPeek) samplerWindow)->hilited);
  197.                 EndUpdate(samplerWindow);
  198.                 break;
  199.             
  200.             case activateEvt:
  201.                 if (theEvent.modifiers & activeFlag)
  202.                 {
  203.                     HiliteControl(rocketCntl, 0);
  204.                     HiliteControl(timeButtonCntl, 0);
  205.                     
  206.                     if (GetCtlValue( timeButtonCntl))
  207.                     {
  208.                         HiliteControl(timeCntl, 0);
  209.                         HiliteControl(dateCntl, 0);
  210.                     }
  211.                     else
  212.                     {
  213.                         HiliteControl(timeCntl, 255);
  214.                         HiliteControl(dateCntl, 255);
  215.                     }
  216.                         
  217.                 }
  218.                 else
  219.                 {    
  220.                     curCntl = ((WindowPeek)samplerWindow)->controlList;
  221.                     while (curCntl)
  222.                     {
  223.                         HiliteControl(curCntl, 255);
  224.                         curCntl = (*curCntl)->nextControl;
  225.                     }
  226.                 }
  227.                 break;
  228.         }
  229. }
  230. /* end HandleEvent */
  231.  
  232.  
  233. /*****
  234.  * main()
  235.  *
  236.  *    This is where everything happens
  237.  *
  238.  *****/
  239.  
  240.  
  241. main()
  242.  
  243. {
  244.     InitMacintosh();
  245.     SetUpMenus();
  246.     SetUpWindow();
  247.     
  248.     for (;;)
  249.         HandleEvent();
  250. }
  251. /* end main */